﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Web.UI;

namespace RyanLam.NET.Templates.AdminControl.MessageBlock
{
    [
    DefaultProperty("Text"),
    ParseChildren(true),
    PersistChildren(false),
    ToolboxData("<{0}:MessageBlock runat=\"server\"></{0}:MessageBlock>")
    ]
    public class MessageBlock : CompositeControl
    {
        #region Private Member Variables
        private MessageBlockIcon icon;
        private Panel message;
        #endregion  
        
        #region Properties

        #region Icon
        /// <summary>
        /// Message block's icon description.
        /// </summary>
        [
        Bindable(true),
        Category("Appearance"),
        DefaultValue(MessageBlockIcon.message),
        Description("Message block's icon description."),
        Localizable(true)
        ]
        public MessageBlockIcon Icon
        {
            get
            {
                return this.icon;
            }
            set
            {
                this.icon = value;
            }
        }
        #endregion

        #region Message
        /// <summary>
        /// Message block's content.
        /// </summary>
        [NotifyParentProperty(true)]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public Panel Message
        {
            get
            {
                return this.message;
            }
            set
            {
                this.message = value;
            }
        }
        #endregion

        #region Overrides
        protected override void RenderContents(HtmlTextWriter writer)
        {
            writer.WriteLine(String.Format(@"<ul class='{0} success grid_12'>", this.icon == null ? "message" : this.Icon.ToString()));
            writer.WriteLine("<li>");
            this.Message.RenderControl(writer);
            writer.WriteLine("</li>");
            writer.WriteLine(@"<li class='close-bt'></li>");
            writer.WriteLine(@"</ul>");
        }
        #endregion
        
        #endregion

    }

    public enum MessageBlockIcon
    { 
        message,
        error
    }
}
